package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.IssuerAndUnitrelation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IIssuerAndUnitrelationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 颁发机构与一级单位关系Controller
 * 
 * @author ess
 * @date 2021-10-18
 */
@RestController
@RequestMapping("/system/issUnitrelation")
public class IssuerAndUnitrelationController extends BaseController
{
    @Autowired
    private IIssuerAndUnitrelationService issuerAndUnitrelationService;

    /**
     * 查询颁发机构与一级单位关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:unitrelation:list')")
    @GetMapping("/list")
    public TableDataInfo list(IssuerAndUnitrelation issuerAndUnitrelation)
    {
        startPage();
        List<IssuerAndUnitrelation> list = issuerAndUnitrelationService.selectIssuerAndUnitrelationList(issuerAndUnitrelation);
        return getDataTable(list);
    }

    /**
     * 导出颁发机构与一级单位关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:unitrelation:export')")
    @Log(title = "颁发机构与一级单位关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(IssuerAndUnitrelation issuerAndUnitrelation)
    {
        List<IssuerAndUnitrelation> list = issuerAndUnitrelationService.selectIssuerAndUnitrelationList(issuerAndUnitrelation);
        ExcelUtil<IssuerAndUnitrelation> util = new ExcelUtil<IssuerAndUnitrelation>(IssuerAndUnitrelation.class);
        return util.exportExcel(list, "颁发机构与一级单位关系数据");
    }

    /**
     * 获取颁发机构与一级单位关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:unitrelation:query')")
    @GetMapping(value = "/{issuerUnitId}")
    public AjaxResult getInfo(@PathVariable("issuerUnitId") String issuerUnitId)
    {
        return AjaxResult.success(issuerAndUnitrelationService.selectIssuerAndUnitrelationByIssuerUnitId(issuerUnitId));
    }

    /**
     * 新增颁发机构与一级单位关系
     */
    @PreAuthorize("@ss.hasPermi('system:unitrelation:add')")
    @Log(title = "颁发机构与一级单位关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IssuerAndUnitrelation issuerAndUnitrelation)
    {
        return toAjax(issuerAndUnitrelationService.insertIssuerAndUnitrelation(issuerAndUnitrelation));
    }

    /**
     * 修改颁发机构与一级单位关系
     */
    @PreAuthorize("@ss.hasPermi('system:unitrelation:edit')")
    @Log(title = "颁发机构与一级单位关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IssuerAndUnitrelation issuerAndUnitrelation)
    {
        return toAjax(issuerAndUnitrelationService.updateIssuerAndUnitrelation(issuerAndUnitrelation));
    }

    /**
     * 删除颁发机构与一级单位关系
     */
    @PreAuthorize("@ss.hasPermi('system:unitrelation:remove')")
    @Log(title = "颁发机构与一级单位关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{issuerUnitIds}")
    public AjaxResult remove(@PathVariable String[] issuerUnitIds)
    {
        return toAjax(issuerAndUnitrelationService.deleteIssuerAndUnitrelationByIssuerUnitIds(issuerUnitIds));
    }
}
